/**
 * 
 */
package ro.utcn.tp.taskManagement.business;

import ro.utcn.tp.taskManagement.model.User;
import ro.utcn.tp.taskManagement.persistence.PersistenceFactory;
import ro.utcn.tp.taskManagement.persistence.UsersPersistence;

/**
 * @author Coni
 * 
 */
public class UsersManager {

	private static UsersManager instance;
	private UsersPersistence usersPersistence;

	private UsersManager() {
		// private constructor
		try {
			usersPersistence = PersistenceFactory.getInstance()
					.getUsersPersistence();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static UsersManager getInstance() {
		if (instance == null) {
			instance = new UsersManager();
		}
		return instance;
	}

	public boolean createUser(User user) {
		try {
			//TODO check if username is not already used getUser(username) in persistence
			 usersPersistence.saveUser(user);
			 return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	public User getUser(String username, String password) {
		try {
			return usersPersistence.getUser(username, password);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
	public User getUser(int userId) {
		try {
			return usersPersistence.getUser(userId);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

}
